import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../../PublicSource/widgets/common_widget.dart';
import '../../../app_files.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'action.dart';
import 'state.dart';

Widget buildView(
    StaffLoginViewState state, Dispatch dispatch, ViewService viewService) {
  return WillPopScope(
      child: Scaffold(
        resizeToAvoidBottomPadding: true,
        backgroundColor: Colors.white,
        body: GestureDetector(
          child: Stack(
            children: [
              Positioned(child: Image.asset(
                'images/staff_bg.png',
                fit: BoxFit.fitWidth,
                width: double.infinity,
              ),top: 0,left: 0,right: 0,),
              Positioned(child:   Image.asset(
                'images/lg_bottom.png',
                width: double.infinity,
                fit: BoxFit.fitWidth,
              ),bottom: 0,left: 0,right: 0,),
              Container(
                width: double.infinity,
                height: double.infinity,
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      Padding( padding: EdgeInsets.only(
                        top: 15 + ScreenUtil.statusBarHeight,
                      ),
                        child:  Stack(
                          children: [
                            Image.asset('images/blue_bg.png',width: 100,height: 100,),
                            Positioned(
                              child: Align(
                                child: Image.asset('images/login_logo.png',width: 85,fit: BoxFit.fitWidth,),
                              ),
                              left: 0,
                              right: 0,
                              top: 0,
                              bottom: 0,
                            ),
                          ],
                        ),),
                      Padding(padding: EdgeInsets.only(right: 16),child: MyInkWellWidget(
                          child: Row(
                            children: [
                              Expanded(child: Container()),
                              Container(
                                decoration: BoxDecoration(
                                  border: Border.all(
                                      color: ThemeConfig.mainColor),
                                  borderRadius: BorderRadius.all(
                                      Radius.circular(5)),
                                ),
                                height: 30,
                                padding:
                                EdgeInsets.only(left: 5, right: 5),
                                child: Row(
                                  children: [
                                    Image.asset('images/lg_change.png'),
                                    Padding(
                                      padding: EdgeInsets.only(left: 4),
                                      child: Text(
                                        '我是用户',
                                        style: TextThemeConfig
                                            .Font13WithMainColor,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                          onTap: () async {
                            final SharedPreferences prefs = await SharedPreferences.getInstance();
                            String phone = prefs.getString('editPhone');
                            String password = prefs.getString('editPassword');
                            Navigator.push(
                                viewService.context,
                                MaterialPageRoute(
                                    builder: (context) {
                                      return AppMainRoutes.routes.buildPage(RoutePath.userLoginView,
                                          {'phone': phone, 'password': password});
                                    },
                                    fullscreenDialog: true));
                          }),),
                      Container(
                        padding:
                        EdgeInsets.only(top: 20, left: 16, right: 16),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.only(
                              topLeft: Radius.circular(20),
                              topRight: Radius.circular(20)),
                          color: Colors.white,
                          boxShadow: [
                            BoxShadow(
                              color: Color(0xff4D81EF),
                              blurRadius: 16,
                            ),
                          ],
                        ),
                        width: double.infinity,
                        height: 420,
                        child: Column(
                          children: [
                            Image.asset('images/staff_login.png'),
                            Container(
                              margin: EdgeInsets.only(top: 20),
                              decoration: BoxDecoration(
                                borderRadius:
                                BorderRadius.all(Radius.circular(5)),
                                color: Color(0xffE8F2FC),
                              ),
                              child: MyInkWellWidget(
                                child: Row(
                                  children: [
                                    Container(
                                      width: 40,
                                      child: Align(
                                        child: Image.asset(
                                            'images/lg_role.png'),
                                      ),
                                    ),
                                    Container(
                                      color: ThemeConfig.rgba(
                                          75, 124, 228, 0.25),
                                      height: 20,
                                      width: 1,
                                    ),
                                    Expanded(
                                      child: Container(
                                        padding: EdgeInsets.only(
                                            left: 14, right: 10),
                                        child: TextField(
                                          textInputAction:
                                          TextInputAction.done,
                                          enabled: false,
                                          controller: state.roleController,
                                          style: TextStyle(
                                              fontSize: 14,
                                              color: ThemeConfig.mainColor),
//                      keyboardType: TextInputType.phone,
                                          decoration: InputDecoration(
                                            border: InputBorder.none,
                                            hintText: "请选择您的角色",
                                            hintStyle: TextStyle(
                                                fontSize: 14,
                                                color:
                                                ThemeConfig.mainColor),
                                          ),
                                        ),
                                      ),
                                    )
                                  ],
                                ),
                                onTap: () => dispatch(
                                    StaffLoginViewActionCreator
                                        .onTapRole()),
                              ),
                            ),
                            Container(
                              margin: EdgeInsets.only(top: 20, bottom: 20),
                              decoration: BoxDecoration(
                                borderRadius:
                                BorderRadius.all(Radius.circular(5)),
                                color: Color(0xffE8F2FC),
                              ),
                              child: Row(
                                children: [
                                  Container(
                                    width: 40,
                                    child: Align(
                                      child: Image.asset(
                                          'images/lg_account.png'),
                                    ),
                                  ),
                                  Container(
                                    color: ThemeConfig.rgba(
                                        75, 124, 228, 0.25),
                                    height: 20,
                                    width: 1,
                                  ),
                                  Expanded(
                                    child: Container(
                                      padding: EdgeInsets.only(
                                          left: 14, right: 10),
                                      child: TextField(
                                        textInputAction:
                                        TextInputAction.done,
                                        controller: state.phoneController,
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: ThemeConfig.mainColor),
//                      keyboardType: TextInputType.phone,
                                        decoration: InputDecoration(
                                          border: InputBorder.none,
                                          hintText: "请输入您的登录账号",
                                          hintStyle: TextStyle(
                                              fontSize: 14,
                                              color: ThemeConfig.mainColor),
                                        ),
                                        onChanged: (String str) {
                                          if (str.length >
                                              ThemeConfig
                                                  .passwordTextLength)
                                            state.phoneController.text =
                                                str.substring(
                                                    0,
                                                    ThemeConfig
                                                        .passwordTextLength);
                                        },
                                      ),
                                    ),
                                  )
                                ],
                              ),
                            ),
                            Container(
                              decoration: BoxDecoration(
                                borderRadius:
                                BorderRadius.all(Radius.circular(5)),
                                color: Color(0xffE8F2FC),
                              ),
                              child: Row(
                                children: [
                                  Container(
                                    width: 40,
                                    child: Align(
                                      child: Image.asset(
                                          'images/lg_password.png'),
                                    ),
                                  ),
                                  Container(
                                    color: ThemeConfig.rgba(
                                        75, 124, 228, 0.25),
                                    height: 20,
                                    width: 1,
                                  ),
                                  Expanded(
                                    child: Container(
                                      padding: EdgeInsets.only(
                                          left: 14, right: 10),
                                      child: TextField(
                                        controller:
                                        state.passwordController,
                                        textInputAction:
                                        TextInputAction.done,
                                        obscureText: true,
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: ThemeConfig.mainColor),
                                        decoration: InputDecoration(
                                          border: InputBorder.none,
                                          hintText: "请输入您的密码",
                                          hintStyle: TextStyle(
                                            fontSize: 14,
                                            color: ThemeConfig.mainColor,
                                          ),
                                        ),
                                        onChanged: (String str) {
                                          if (str.length >
                                              ThemeConfig
                                                  .passwordTextLength)
                                            state.passwordController.text =
                                                str.substring(
                                                    0,
                                                    ThemeConfig
                                                        .passwordTextLength);
                                        },
                                      ),
                                    ),
                                  )
                                ],
                              ),
                            ),
                            Expanded(child: Container()),
                            Container(
                              margin: EdgeInsets.only(
                                  left: 17, right: 17, bottom: 35),
                              height: 50,
                              decoration: BoxDecoration(
                                color: ThemeConfig.mainColor,
                                borderRadius:
                                BorderRadius.all(Radius.circular(4)),
                              ),
                              child: InkWell(
                                child: Center(
                                  child: Text(
                                    '立即登陆',
                                    style: TextThemeConfig
                                        .Font18WithColorWhite,
                                  ),
                                ),
                                onTap: () => dispatch(
                                    StaffLoginViewActionCreator.onSubmit()),
                              ),
                            ),
                          ],
                        ),
                        margin: EdgeInsets.only(left: 17,right: 17,top: 14),
                      ),
                    ],
                  ),
                ),
              ),

            ],
          ),
          behavior: HitTestBehavior.translucent,
          onTap: () => CommonUtils.closeKey(viewService.context),
        ),
      ),
      onWillPop: () async {
        return false;
      });
}
